package com.th.util;

import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;

import java.util.List;

/**
 * 校验字符合法性
 */
public class ErrorBindingResult {
    public static  MyJson returnError(BindingResult bindingResult){
        StringBuffer msg=new StringBuffer();
        if(bindingResult.hasErrors()){
            List<ObjectError> allErrors = bindingResult.getAllErrors();
            for (ObjectError error:allErrors) {
                msg.append(error.getDefaultMessage());

            }
        }
        if(msg.equals("")){
            return null;
        }else {
            return MyJson.ook(msg.toString());
        }
    }
}
